package com.ibeeking.found.content.c.rest.controller.v1;

import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.content.c.rest.service.IArticleCommentService;
import com.ibeeking.found.content.c.rest.service.IArticleGroupService;
import com.ibeeking.found.content.c.rest.service.IArticleService;
import com.ibeeking.found.content.service.common.param.ArticleCommentParam;
import com.ibeeking.found.content.service.common.query.*;
import com.ibeeking.found.content.service.common.vo.ArticleCommentVO;
import com.ibeeking.found.content.service.common.vo.ArticleGroupVO;
import com.ibeeking.found.content.service.common.vo.ArticleVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ArticleController控制器
 * @Description
 * @Author ibeeking
 * @Date 2022-02-18 14:11
 **/
@RestController
@RequestMapping("/c/article/v1")
public class ArticleController {

    @Resource
    private IArticleService articleServiceImpl;
    @Resource
    private IArticleGroupService articleGroupServiceImpl;
    @Resource
    private IArticleCommentService articleCommentServiceImpl;


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章列表")
    @PostMapping(value = "/list")
    public List<ArticleVO> list(@RequestBody ArticleQuery articleQuery) {
        return articleServiceImpl.list(articleQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章分页列表")
    @PostMapping(value = "/pageList")
    public Page<ArticleVO> pageList(@RequestBody ArticlePageQuery articlePageQuery) {
        return articleServiceImpl.pageList(articlePageQuery);
    }


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章查看")
    @GetMapping(value = "/view/{id}")
    public ArticleVO view(@PathVariable("id") Long id) {
        return articleServiceImpl.view(id);
    }

    /**
     * ------------文章分组
     */

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章分组列表")
    @PostMapping(value = "/group/list")
    public List<ArticleGroupVO> groupList(@RequestBody ArticleGroupQuery articleGroupQuery) {
        return articleGroupServiceImpl.list(articleGroupQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章分组分页列表")
    @PostMapping(value = "/group/pageList")
    public Page<ArticleGroupVO> groupPageList(@RequestBody ArticleGroupPageQuery articleGroupPageQuery) {
        return articleGroupServiceImpl.pageList(articleGroupPageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文章分组查看")
    @GetMapping(value = "/group/view/{id}")
    public ArticleGroupVO groupView(@PathVariable("id") Long id) {
        return articleGroupServiceImpl.view(id);
    }

    /**
     * 评论管理
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "评论分页列表")
    @PostMapping(value = "/comment/pageList")
    public Page<ArticleCommentVO> commentPageList(@RequestBody ArticleCommentPageQuery articleCommentPageQuery) {
        articleCommentPageQuery.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return articleCommentServiceImpl.pageList(articleCommentPageQuery);
    }

    /**
     * 评论管理
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "评论保存")
    @PostMapping(value = "/comment/save")
    public Boolean commentSave(@RequestBody ArticleCommentParam articleCommentParam) {
        return articleCommentServiceImpl.save(articleCommentParam);
    }

}
